package elevation.general;

import android.app.Dialog;
import android.content.Context;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Handler;
import android.view.Window;

import com.google.android.maps.MapActivity;

public class BaseActivity extends MapActivity {
	protected final Handler mHandler = new Handler();
	protected Dialog mProgressDialog;

	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}

	protected void showProgressAsync() {

		mHandler.post(new Runnable() {

			public void run() {
				if (mProgressDialog == null) {
					mProgressDialog = new Dialog(BaseActivity.this, android.R.style.Theme_Translucent_NoTitleBar);
					mProgressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
					mProgressDialog.setContentView(R.layout.progress_layout);
					mProgressDialog.setCancelable(false);
					mProgressDialog.show();
				}

			}
		});
	}

	protected void showProgressAsyncCancelable(final LocationListener locationListener, final Context context,
			final LocationManager locationManager) {
		mHandler.post(new Runnable() {

			public void run() {
				if (mProgressDialog == null) {
					mProgressDialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar) {

						@Override
						public void onBackPressed() {
							locationManager.removeUpdates(locationListener);
							hideProgressAsync();
							super.onBackPressed();
						}
					};
					mProgressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
					mProgressDialog.setContentView(R.layout.progress_layout);
					mProgressDialog.show();
				}
			}
		});
	}

	public void hideProgressAsync() {
		mHandler.post(new Runnable() {

			public void run() {
				if (mProgressDialog != null) {
					try {
						mProgressDialog.dismiss();
					} catch (Exception e) {

					} finally {
						mProgressDialog = null;
					}
				}
			}
		});

	}

}
